package com.yeung.annotation;

import com.yeung.annotation.controller.UserController;
import com.yeung.annotation.entity.Person;
import com.yeung.annotation.repository.UserRepositoryImp;
import com.yeung.annotation.service.UserService;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    /**
     * 虽然这些bean都没有再bean文件配置, 但是我们使用了注解,并配置了spring扫描注解
     * 一次可以拿到它的实例
     */
    @Test
    public void 配置扫描包里的注解() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans-annotation.xml");
        Person person = (Person) context.getBean("person");
        System.out.println(person);
        UserRepositoryImp userRepository = (UserRepositoryImp) context.getBean("userRepository");
        System.out.println(userRepository);
        UserController userController = (UserController) context.getBean("userController");
        System.out.println(userController);
        UserService userService = (UserService) context.getBean("userService");
        System.out.println(userService);
        userController.excute();

    }

}
